<?php
  header("Content-Type: application/xhtml+xml; charset=UTF-8");
  ob_start();
session_start();?>
  
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:my="http://example.com/my" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:svg="http://www.w3.org/2000/svg" xmlns:s="http://www.example.com/sudoku" xmlns:b="http://www.example.com/board" xmlns:sq="http://www.example.com/squares">
		<head>
				<title>Sudoku</title>
				<link rel="stylesheet" type="text/css" href="sudoku.css"/>
				
				<xforms:model schema="./sudoku.xsd">
						<xforms:instance id="content">
								<?php
									include './convert.php';
								?>
						</xforms:instance>
						<xforms:bind nodeset="//s:row//s:box[@s:ro='yes']" readonly="true()"/>
						<xforms:bind nodeset="//s:submitButtonElement" relevant="/s:game/s:correctRows = 27"/>
						<xforms:bind nodeset="//s:correctRows" calculate="count(/s:game/s:row[s:box = '1'][s:box = '2'][s:box = '3'][s:box = '4'][s:box = '5'][s:box = '6'][s:box = '7'][s:box = '8'][s:box = '9']) +       
												count(/s:game[s:row[s:box[1]='1']][s:row[s:box[1]='2']] [s:row[s:box[1]='3']][s:row[s:box[1]='4']][s:row[s:box[1]='5']] [s:row[s:box[1]='6']][s:row[s:box[1]='7']][s:row[s:box[1]='8']] [s:row[s:box[1]='9']]) +       
												count(/s:game[s:row[s:box[2]='1']][s:row[s:box[2]='2']] [s:row[s:box[2]='3']][s:row[s:box[2]='4']][s:row[s:box[2]='5']] [s:row[s:box[2]='6']][s:row[s:box[2]='7']][s:row[s:box[2]='8']] [s:row[s:box[2]='9']]) +       
												count(/s:game[s:row[s:box[3]='1']][s:row[s:box[3]='2']] [s:row[s:box[3]='3']][s:row[s:box[3]='4']][s:row[s:box[3]='5']] [s:row[s:box[3]='6']][s:row[s:box[3]='7']][s:row[s:box[3]='8']] [s:row[s:box[3]='9']]) +       
												count(/s:game[s:row[s:box[4]='1']][s:row[s:box[4]='2']] [s:row[s:box[4]='3']][s:row[s:box[4]='4']][s:row[s:box[4]='5']] [s:row[s:box[4]='6']][s:row[s:box[4]='7']][s:row[s:box[4]='8']] [s:row[s:box[4]='9']]) +       
												count(/s:game[s:row[s:box[5]='1']][s:row[s:box[5]='2']] [s:row[s:box[5]='3']][s:row[s:box[5]='4']][s:row[s:box[5]='5']] [s:row[s:box[5]='6']][s:row[s:box[5]='7']][s:row[s:box[5]='8']] [s:row[s:box[5]='9']]) +       
												count(/s:game[s:row[s:box[6]='1']][s:row[s:box[6]='2']] [s:row[s:box[6]='3']][s:row[s:box[6]='4']][s:row[s:box[6]='5']] [s:row[s:box[6]='6']][s:row[s:box[6]='7']][s:row[s:box[6]='8']] [s:row[s:box[6]='9']]) +       
												count(/s:game[s:row[s:box[7]='1']][s:row[s:box[7]='2']] [s:row[s:box[7]='3']][s:row[s:box[7]='4']][s:row[s:box[7]='5']] [s:row[s:box[7]='6']][s:row[s:box[7]='7']][s:row[s:box[7]='8']] [s:row[s:box[7]='9']]) +       
												count(/s:game[s:row[s:box[8]='1']][s:row[s:box[8]='2']] [s:row[s:box[8]='3']][s:row[s:box[8]='4']][s:row[s:box[8]='5']] [s:row[s:box[8]='6']][s:row[s:box[8]='7']][s:row[s:box[8]='8']] [s:row[s:box[8]='9']]) +       
												count(/s:game[s:row[s:box[9]='1']][s:row[s:box[9]='2']] [s:row[s:box[9]='3']][s:row[s:box[9]='4']][s:row[s:box[9]='5']] [s:row[s:box[9]='6']][s:row[s:box[9]='7']][s:row[s:box[9]='8']] [s:row[s:box[9]='9']]) +        
												count(/s:game/s:square[s:box = '1'][s:box = '2'][s:box = '3'][s:box = '4'][s:box = '5'][s:box = '6'][s:box = '7'][s:box = '8'][s:box = '9'])"/>
                                               
                                              
											 
						<xforms:instance id="templates">
								<b:template>
										<b:entry>
												<b:sendvalue>0</b:sendvalue>
												<b:display/>
										</b:entry>
										<b:entry>
												<b:sendvalue>1</b:sendvalue>
												<b:display>1</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>2</b:sendvalue>
												<b:display>2</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>3</b:sendvalue>
												<b:display>3</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>4</b:sendvalue>
												<b:display>4</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>5</b:sendvalue>
												<b:display>5</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>6</b:sendvalue>
												<b:display>6</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>7</b:sendvalue>
												<b:display>7</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>8</b:sendvalue>
												<b:display>8</b:display>
										</b:entry>
										<b:entry>
												<b:sendvalue>9</b:sendvalue>
												<b:display>9</b:display>
										</b:entry>
								</b:template>
						</xforms:instance>
						<xforms:submission id="submitgame" action="http://localhost:81/a/convert.php"   replace="instance" instance="content"  method="post"/>
						<xforms:submission id="savegame" action="file:///c:/sudoku.txt" replace="instance" instance="content" method="put"/>
						<xforms:submission id="loadgame" action="file:///c:/sudoku.txt" replace="instance" instance="content" method="get"/>
				</xforms:model>
				
				
		</head>
		<body>
				<h1 align="center">Sudoku</h1>
				<br clear="left"/>
				
				<div>
						<xforms:repeat id="gamerow" nodeset="instance('content')/s:row">
								<xforms:repeat id="gamebox" nodeset="s:box">
										<span>
												<xforms:input ref=".">
														<xforms:action ev:event="xforms-invalid">
																<xforms:setvalue ref="."/>
																<xforms:message level="modal">Please choose an integer from 1 to 9.</xforms:message>
														</xforms:action>
												</xforms:input>
										</span>
								</xforms:repeat>
						</xforms:repeat>
				</div>

    Correct : <xforms:output ref="//s:correctRows"/>
				<br/>
				<xforms:trigger style="display:block">
						<xforms:label>Check it!</xforms:label>
						<xforms:action ev:event="DOMActivate">
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[1]" value="/s:game/s:row[1]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[2]" value="/s:game/s:row[1]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[3]" value="/s:game/s:row[1]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[4]" value="/s:game/s:row[2]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[5]" value="/s:game/s:row[2]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[6]" value="/s:game/s:row[2]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[7]" value="/s:game/s:row[3]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[8]" value="/s:game/s:row[3]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[1]/s:box[9]" value="/s:game/s:row[3]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[1]" value="/s:game/s:row[1]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[2]" value="/s:game/s:row[1]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[3]" value="/s:game/s:row[1]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[4]" value="/s:game/s:row[2]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[5]" value="/s:game/s:row[2]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[6]" value="/s:game/s:row[2]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[7]" value="/s:game/s:row[3]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[8]" value="/s:game/s:row[3]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[2]/s:box[9]" value="/s:game/s:row[3]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[1]" value="/s:game/s:row[1]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[2]" value="/s:game/s:row[1]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[3]" value="/s:game/s:row[1]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[4]" value="/s:game/s:row[2]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[5]" value="/s:game/s:row[2]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[6]" value="/s:game/s:row[2]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[7]" value="/s:game/s:row[3]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[8]" value="/s:game/s:row[3]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[3]/s:box[9]" value="/s:game/s:row[3]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[1]" value="/s:game/s:row[4]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[2]" value="/s:game/s:row[4]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[3]" value="/s:game/s:row[4]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[4]" value="/s:game/s:row[5]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[5]" value="/s:game/s:row[5]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[6]" value="/s:game/s:row[5]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[7]" value="/s:game/s:row[6]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[8]" value="/s:game/s:row[6]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[4]/s:box[9]" value="/s:game/s:row[6]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[1]" value="/s:game/s:row[4]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[2]" value="/s:game/s:row[4]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[3]" value="/s:game/s:row[4]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[4]" value="/s:game/s:row[5]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[5]" value="/s:game/s:row[5]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[6]" value="/s:game/s:row[5]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[7]" value="/s:game/s:row[6]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[8]" value="/s:game/s:row[6]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[5]/s:box[9]" value="/s:game/s:row[6]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[1]" value="/s:game/s:row[4]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[2]" value="/s:game/s:row[4]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[3]" value="/s:game/s:row[4]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[4]" value="/s:game/s:row[5]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[5]" value="/s:game/s:row[5]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[6]" value="/s:game/s:row[5]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[7]" value="/s:game/s:row[6]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[8]" value="/s:game/s:row[6]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[6]/s:box[9]" value="/s:game/s:row[6]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[1]" value="/s:game/s:row[7]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[2]" value="/s:game/s:row[7]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[3]" value="/s:game/s:row[7]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[4]" value="/s:game/s:row[8]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[5]" value="/s:game/s:row[8]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[6]" value="/s:game/s:row[8]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[7]" value="/s:game/s:row[9]/s:box[1]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[8]" value="/s:game/s:row[9]/s:box[2]"/>
								<xforms:setvalue ref="/s:game/s:square[7]/s:box[9]" value="/s:game/s:row[9]/s:box[3]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[1]" value="/s:game/s:row[7]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[2]" value="/s:game/s:row[7]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[3]" value="/s:game/s:row[7]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[4]" value="/s:game/s:row[8]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[5]" value="/s:game/s:row[8]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[6]" value="/s:game/s:row[8]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[7]" value="/s:game/s:row[9]/s:box[4]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[8]" value="/s:game/s:row[9]/s:box[5]"/>
								<xforms:setvalue ref="/s:game/s:square[8]/s:box[9]" value="/s:game/s:row[9]/s:box[6]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[1]" value="/s:game/s:row[7]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[2]" value="/s:game/s:row[7]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[3]" value="/s:game/s:row[7]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[4]" value="/s:game/s:row[8]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[5]" value="/s:game/s:row[8]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[6]" value="/s:game/s:row[8]/s:box[9]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[7]" value="/s:game/s:row[9]/s:box[7]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[8]" value="/s:game/s:row[9]/s:box[8]"/>
								<xforms:setvalue ref="/s:game/s:square[9]/s:box[9]" value="/s:game/s:row[9]/s:box[9]"/>
						</xforms:action>
				</xforms:trigger>
				<xforms:submit ref="/s:game/s:submitButtonElement" submission="submitgame">
						<xforms:label>Submit</xforms:label>
				</xforms:submit>	

				<form action="" method="post">
                 <select sel_id="" id="category_group" name="lvgame" class="">
                                     
                                      <option value="1">Dễ </option>               		 					
                    
                      <option   value="2">TB</option>                   	 							                      <option   value="3">Kho</option>        
                        	
                                          
                                  </select>
					<input type="submit" name="taomoi" value="NewGame" />
                   
				</form>
			<?php 
				if(isset($_POST["taomoi"]))
				{
					$lv = $_POST["lvgame"];
					$_SESSION["lvgame"]=$_POST["lvgame"];
					 header("refresh:0;url=sudoku.php");
					
				}
			?>
			
			 
				 
				
				<script>
function reloadPage()
  {
  alert('bạn là người chiến thắng!');
  window.location.reload();
  }
</script>
 
 

			<form action="" method="post">
					<input type="submit" name="savegame"  value="savegame" />
				</form>
                <?php
				
					if(isset($_POST["savegame"]))
					{
						  
						 
								?><script>							 
							  		alert('Da luu Thanh Cong!');						   
							   
							</script><?php
 
					}
				?>


<form action="" method="post">
					<input type="submit" name="LoadGame"  value="LoadGame" />
				</form>
                <?php
				
					if(isset($_POST["LoadGame"]))
					{
						 
						  header("refresh:1;url=LoadGame.php");
					}
				?>
<form action="" method="post">
					<input type="submit" name="dapan"  value="DapAn" />
				</form>
                <?php
				
					if(isset($_POST["dapan"]))
					{
						$_SESSION["Game"]=$nextGame;
						  header("refresh:0;url=dapan.php");
					}
				?>

		</body>
</html>